<template>
  <div>
    <el-table
      border
      :data="highdata"
      style="width: 100%"
      :default-sort = "{prop: 'createTime', order: 'descending'}"
    >
      <el-table-column
        prop="userId"
        label="ID"
        sortable
        width="70">
      </el-table-column>
      <el-table-column
        prop="hostName"
        label="姓名"
        width="80">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号"
        width="130">
      </el-table-column>
      <el-table-column
        prop="idNumber"
        label="身份证号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="200"
        :show-overflow-tooltip="true"
        :formatter="formatter">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        sortable
        width="180">
      </el-table-column>
      <el-table-column
        prop="enabledSuggest"
        label="未通过原因"
        width="160">
        <template slot-scope="scope">
          {{scope.row.enabledSuggest}}
        </template>
      </el-table-column>
      <el-table-column
        label="状态"
        prop="enabled"
        width="100">
        <template slot-scope="scope">
          <el-button type="primary" size="mini"  plain
            @click="showEditView(scope.$index, scope.row,true)">
            {{scope.row.enabled===0?'未审核':''}}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
      title="用户认证审核"
      :visible.sync="dialogFormVisible"
      width="800px">
      <el-descriptions class="margin-top" title="用户信息" :column="3" :size="size" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            用户名
          </template>
          {{highdata.hostName}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            手机号
          </template>
          {{highdata.phone}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-s-promotion"></i>
            邮箱
          </template>
          {{highdata.email}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets"></i>
            身份证号
          </template>
          {{highdata.idNumber}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building"></i>
            地址
          </template>
          {{highdata.address}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-bell"></i>
            提交时间
          </template>
          {{highdata.createTime}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-edit-outline"></i>
            原因
          </template>
          {{highdata.enabledSuggest?highdata.enabledSuggest:'未审核'}}
        </el-descriptions-item>
      </el-descriptions>
      <div class="suggest">
        <div style="margin-bottom: 10px;margin-top: 20px">
          活动区域：
          <el-select v-model="comfirm.enabled" placeholder="请选择审核结果" size="small">
            <el-option v-for="item in options" :key="item.value" :value="item.value" :label="item.label"></el-option>
          </el-select>
        </div>
        <div v-if="comfirm.enabled===2" style="margin-bottom: 10px">
          审核建议：
          <el-autocomplete class="inline-input"
                           v-model="comfirm.enabledSuggest"
                           :fetch-suggestions="querySearch"
                           placeholder="请输入内容"
                           :style="{width: '40%'}"
                           size="small">
          </el-autocomplete>
        </div>
        <div slot="footer" style="margin-left: 580px">
          <el-button size="small" @click="doCancel" type="danger">取消</el-button>
          <el-button size="small" type="success" @click="doUpdate">确定</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'PerComfirm',
    data() {
      return {
        options: [{
          value: 1,
          label: '通过'
        }, {
          value: 2,
          label: '不通过'
        }],
        comfirm:{
          comfirmId:undefined,
          enabledSuggest: '',
          enabled:'',
        },
        selectKey:'',
        highdata:{
          comfirmId:undefined,
          userId:undefined,
          hostName:'',
          phone:undefined,
          idNumber:undefined,
          email:undefined,
          createTime:'',
          address:'',
          enabled:undefined,
          region: undefined,
          enabledSuggest:''
        },
        dialogFormVisible:false,
        size: 'medium',
        restaurants: [],
      }
    },
    mounted () {
      this.initTable();
      this.restaurants = this.loadAll();
    },
    methods: {
      //显示弹出框赋值
      doUpdate(){
        this.comfirm.comfirmId=this.highdata.comfirmId
        if (this.comfirm.enabled===2||this.comfirm.enabled===1){
          this.putRequest('/personal/data/comfirm/',this.comfirm).then(resp=>{
            if (resp){
              this.dialogFormVisible=false;
              this.initTable();
              this.$notify.success({ title: '成功', message:resp.message});

            }
          })
        } else {
          this.$notify.error({ title: '失败', message: '请输入审核状态' });
        }
      },
      doCancel(){
        this.$notify.info({ title: '消息', message: '取消修改'});
        this.dialogFormVisible = false;
      },
      showEditView(index,data){
        this.comfirm.enabled='';
        Object.assign(this.highdata,data);
        this.dialogFormVisible=true;
        // Object.assign(this.good,data);
      },
      formatter(row, column) {
        return row.address;
      },
      initTable(){
        this.getRequest('/personal/data/comfirm/notEnable/').then(resp => {
          if (resp) {
            console.log(resp);
            this.highdata = resp;
          }
        })
      },
      querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      loadAll() {
        return [
          { "value": "姓名与身份证号不符"},
          { "value": "地址不存在"},
          { "value": "手机号为空"},
          { "value": "邮箱为空"}
        ];
      },
    }
  }
</script>

<style scoped>
.suggest{
  margin-left: 25px;
}
</style>
